import * as types from '../types'
import common from "api/common";

let tencent = window.location.hash.split('/')[3]||sessionStorage.getItem('tencentId') || 1
const state={
  code:common.getVal('code'+tencent,null)||'',//021YpS0009UBbM1zl9200hclMo2YpS03
  openid:common.getVal('openid'+tencent,null)||'',//oJdKL6Yen6JG-bYf-NCQDeKScP6w oswq550FIVVmCMsWFrNGX21E34w0
  page_access_token:common.getVal('page_access_token'+tencent,null)||"",//47__Q5SRFqIHxWB0tXwo-heHoP7xGLJNktkGcdVdMpRjmC9G9ApE8zfba6N0KllxM5dA_VzHmMUNfzQbJMgC7VNHw
  wxUserInfo:common.getVal('wxUserInfo',null)||{},
  phoneNo:localStorage.getItem('phoneNo')||''
}

const getters={
  code:state=>state.code,
  openid:state=>state.openid,
  page_access_token:state=>state.page_access_token,
  wxUserInfo:state=>state.wxUserInfo,
  phoneNo:state=>state.phoneNo,
}

const mutations={
  [types.SET_WX_CODE](state,res){
    common.setVal('code', res)
    state.code=res
  },
  [types.SET_OPENID](state,res){
    common.setVal('openid'+tencent, res.openid)
    common.setVal('page_access_token'+tencent, res.token)
    state.openid=res.openid
    state.page_access_token=res.token
  },
  setWxUserInfo(state,res){
    common.setVal('wxUserInfo', res)
    state.wxUserInfo=res
  },
  setPhoneNo(state,res){
    localStorage.setItem('phoneNo',res)
    state.phoneNo=res
  }
}

const actions={}

export default {
  namespaced:true,
  state,
  getters,
  actions,
  mutations
}
